<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
    // 利用new创建数组
         arr = new Array();
    // 利用数组字面量创建数组
        var arr = []; // 创建了一个空的数组
        var arr1 = [1, 2, 'pink老师', true];
        console.log (arr1);
        var week = ['星期一','星期二','星期三'];
        for (var i = 0; i < week.length; i++)
        console.log(week[i]);
        console.log(week.length);
    // 新增数组元素，修改length长度
        week.length = 7;
        console.log(week[4]);
    // 修改索引号，追加数组元素
        week[5] = '星期六';
        console.log(week);
    // 不要直接给数组名赋值，会覆盖掉以前的数据
        var arr2 = [];
        for ( var i = 0; i < 10 ;i++) {
            arr2[i]= i+1;
        }
        console.log(arr2);
    var arr = [2, 0, 6, 1, 77, 0, 52, 0, 25, 7];
    var newArr = [];
    for(var i = 0; i < arr.length; i++) {
        if (arr[i] != 0) {
            newArr[newArr.length] = arr[i];
        }
    }
    console.log(newArr);
        var arr = [1, 2, 3, 4, 5];
        var newArr = [2, 0, 6, 1, 77, 0, 52, 0, 25, 7];
        for ( var i = arr.length - 1; i >= 0; i--) {
            newArr[newArr.length] = arr [i];
        }
        console.log(newArr);
        // 从第0个数组元素开始，比较与下一个数组元素的大小，若比下一个大，则交换二者的位置，否则不交换。
        // 完成每次交换后，数组元素下标加1,遍历的长度减1,交换轮次为length-1次
        for (var i = 0; i < newArr.length - 1 ; i++) {
            for ( var j = 0; j < newArr.length - i -1; j++) {
                if (newArr[j] > newArr[j+1]) {
                    var temp = newArr[j];
                    newArr[j] = newArr[j+1];
                    newArr[j+1] = temp; 
                }
            }
        }
        console.log(newArr);
    </script>
</head>
<body>
    
</body>
</html>